﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using TRPOP.Common;
using TRPOP.CMS.Web.UI;


using TRPOP.CMS.Business;
using TRPOP.CMS.Model;
using System.Collections;
using TRPOP.Cache;
using TRPOP.CMS.Plugin;

namespace TRPOP.CMS.Web.Admin
{
    public partial class CacheSetting : BaseAdmin
    {
        #region 当前页面权限验证
        protected override void SubPageInit()
        {
            base.m_SubPagePermission = Plugin.PermissionKeys.PermissionEnum.SystemManage_Cache;
        }
        #endregion

        #region 页面变量
        protected string m_Title = "缓存";
        protected string m_strRefer = "CacheSetting.aspx";
        #endregion

        #region 页面事件

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadBase();
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            base.SaveLog(LogKeys.OperObject.CacheOper, LogKeys.OperResult.DelSubmit);

            SYSConfig.Cache_Enable = rbtCacheEnable.SelectedValue.ToBool();

            foreach (ListItem oListItem in chkClearCacheList.Items)
            {
                if (oListItem.Selected)
                    ICacheAccess.GetInstance().RemoveByRegexp(oListItem.Value);
            }

            SubmitAlertAndThisNewLocation(true, m_strRefer);
        }

        protected void btnClearAll_Click(object sender, EventArgs e)
        {
            base.SaveLog(LogKeys.OperObject.CacheOper, LogKeys.OperResult.DelSubmit);

            ICacheAccess.GetInstance().Clear();

            SubmitAlertAndThisNewLocation(true, m_strRefer);
        }

        #endregion

        #region 页面方法

        public void LoadBase()
        {
            rbtCacheEnable.SelectedValue = SYSConfig.Cache_Enable ? "1" : "0";

            chkClearCacheList.DataSource = CacheKeys.GetAllCacheClearKeys();
            chkClearCacheList.DataTextField = "key";
            chkClearCacheList.DataValueField = "value";

            chkClearCacheList.DataBind();
        }
        #endregion
    }
}
